<?php 
class rss{
	var $title;
	var $content;
	var $main_link;

	/*
	Khởi tạo class
	*/
	function rss($title, $main_link=""){
		$this->title 		= $title;
		$this->main_link 	= $main_link;
		$this->content 	= "";
        $this->copyright = DOMAIN;
        $this->generator = SITENAME;
	}

	/*
	Print header
	*/
	function rss_header(){
		$today = getdate();

		$header = '<?xml version="1.0" encoding="utf-8"?>' . "\n" .
				    '<rss version="2.0">' . "\n" .
					 '	<channel>'  . "\n" .
					 '		<title>' . htmlspecialchars($this->title) . '</title>' . "\n" .
                     '		<copyright>' . htmlspecialchars($this->copyright) . '</copyright>' . "\n" .
                     '		<generator>' . htmlspecialchars($this->generator) . '</generator>' . "\n" .
					 '		<link>' . htmlspecialchars($this->main_link) . '</link>' . "\n" .
					 '		<pubDate>' . date("D, d M Y H:i:s ",$today[0]) . "GMT+7" . '</pubDate>' . "\n" .
					 '		<lastBuildDate>' . date("D, d M Y H:i:s ",$today[0]) . "GMT+7" . '</lastBuildDate>' . "\n";

		return $header;
	}

	/*
	Add item
	*/
	function additem($title, $description, $link, $guid = '' , $pubdate){
		$item = '			<item>' . "\n" .
				  '				<title>' . htmlspecialchars($title) . '</title>' . "\n" .
				  '				<description><![CDATA[' . $description . ']]></description>' . "\n" .
				  '				<link>' . htmlspecialchars($link) . '</link>' . "\n" .
                  '				<guid isPermaLink="false">' . htmlspecialchars($guid) . '</guid>' . "\n" .
				  '				<pubDate>' . htmlspecialchars($pubdate) . '</pubDate>' . "\n" .
				  '			</item>' . "\n";

		//return $item;
		$this->content .= $item;
	}

	/*
	Print header
	*/
	function rss_footer(){
		$footer = '	</channel>' . "\n" .
					 '</rss>';

		return $footer;
	}

	/*
	lấy nội dung rss
	*/
	function getRSSContent(){
		return $this->rss_header() .
				 $this->content .
				 $this->rss_footer();
	}

	/*
	Save RSS to file
	*/
	function saveRSS($filename){
		$handle = fopen($filename, 'w');
		fwrite($handle, $this->getRSSContent());
		fclose($handle);
	}
}
?>